﻿export default function define(Blocks: Blockly.BlockDefinitions) {
  Blocks['import_turtle'] = {
    init: function () {
      this.appendDummyInput()
        .appendField("导入 turtle 海龟画图库");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("导入库");
      this.setHelpUrl("");
    }
  };

  Blocks['turtle'] = {
    init: function () {
      this.appendDummyInput()
      .appendField("定义");
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("turtle"), "turtle")
        .appendField("为Turtle实例");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("初始化");
      this.setHelpUrl("");
    }
  };

  Blocks['screeninit'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("screen"), "wn")
        .appendField(" 是Screen实例");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("初始化");
      this.setHelpUrl("");
    }
  };

  Blocks['background'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("screen"), "wn")
        .appendField("背景颜色(")
      this.appendValueInput('text')
        .setCheck(null);
      this.appendDummyInput()
        .appendField(")");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("改变背景");
      this.setHelpUrl("");
    }
  };

  Blocks['directions'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("turtle"), "turtle")
        .appendField(".")
        .appendField(new Blockly.FieldDropdown([["向前", "forward"], ["后退", "backward"]]), "options")
        .appendField("(")
      this.appendValueInput('text')
        .setCheck(null);
      this.appendDummyInput()
        .appendField(")像素");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("移动");
      this.setHelpUrl("");
    }
  };
  
   Blocks['directions1'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("turtle"), "turtle")
        .appendField(".")
        .appendField(new Blockly.FieldDropdown([["向左", "left"], ["向右", "right"]]), "options")
        .appendField("(")
      this.appendValueInput('text')
        .setCheck(null);
      this.appendDummyInput()
        .appendField(")度角");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("移动");
      this.setHelpUrl("");
    }
  };

  Blocks['penud'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("turtle"), "turtle")
        .appendField(".笔")
        .appendField(new Blockly.FieldDropdown([["抬起", "up"], ["放下", "down"]]), "options");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("提起笔移动");
      this.setHelpUrl("");
    }
  };

  Blocks['pen'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("turtle"), "turtle")
        .appendField(".pen()");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("初始化pen");
      this.setHelpUrl("");
    }
  };

  Blocks['colourpen'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("turtle"), "turtle")
        .appendField(".笔的颜色(")
      this.appendValueInput('text')
        .setCheck(null);
      this.appendDummyInput()
        .appendField(")");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("改变笔的颜色");
      this.setHelpUrl("");
    }
  };

  Blocks['colour'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("turtle"), "turtle")
        .appendField(".颜色是(")
      this.appendValueInput('text')
        .setCheck(null);
      this.appendDummyInput()
        .appendField(")");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("改变颜色");
      this.setHelpUrl("");
    }
  };

  Blocks['colourmode'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("screen"), "wn")
        .appendField(".颜色模式:")
      this.appendDummyInput()
        .appendField("红");
      this.appendValueInput('value_red')
        .setCheck(null);
      this.appendDummyInput()
        .appendField("绿");
      this.appendValueInput('value_green')
        .setCheck(null);
      this.appendDummyInput()
        .appendField("蓝");
      this.appendValueInput('value_blue')
        .setCheck(null);
      this.appendDummyInput()
        .appendField(")");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("改变颜色模式");
      this.setHelpUrl("");
    }
  };

  Blocks['penwidth'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("turtle"), "turtle")
        .appendField(".宽度(")
      this.appendValueInput('text')
        .setCheck(null);
      this.appendDummyInput()
        .appendField(")");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("改变宽度");
      this.setHelpUrl("");
    }
  };
  
  Blocks['turtlespeed'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("turtle"), "turtle")
        .appendField(".画图速度(")
      this.appendValueInput('text')
        .setCheck(null);
      this.appendDummyInput()
        .appendField(")");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("改变速度");
      this.setHelpUrl("");
    }
  };

  Blocks['turtleshape'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("turtle"), "turtle")
        .appendField(".笔形状(")
      this.appendValueInput('text')
        .setCheck(null);
      this.appendDummyInput()
        .appendField(")");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("改变形状");
      this.setHelpUrl("");
    }
  };

  Blocks['circle'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("turtle"), "turtle")
        .appendField(".画圆(")
      this.appendValueInput('text')
        .setCheck(null);
      this.appendDummyInput()
        .appendField(")");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
        this.setTooltip("画圆");
      this.setHelpUrl("");
    }
  };

  Blocks['goto'] = {
    init: function () {
      this.appendDummyInput()
        .appendField(new Blockly.FieldVariable("turtle"), "turtle")
        .appendField(".跳转到(")
      this.appendValueInput('text')
        .setCheck(null);
      this.appendDummyInput()
        .appendField(")");
      this.setPreviousStatement(true, null);
      this.setNextStatement(true, null);
      this.setColour(240);
      this.setTooltip("跳往 x&y");
      this.setHelpUrl("");
    }
  };
}
